package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.MallBean;
import com.mz.ozy.bean.ShopDetailBean;
import com.mz.ozy.utils.ScreenUtil;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import java.util.List;

/**
 * Created by administrator on 2018/11/21.
 */
public class ShopEvaluateAdapter extends BaseQuickAdapter<ShopDetailBean.ComListBean, BaseViewHolder> {


    public ShopEvaluateAdapter(@Nullable List<ShopDetailBean.ComListBean> data) {
        super(R.layout.item_food_evaluate, data);
//        addData(new MallBean.KtProductListBean());
//        addData(new MallBean.KtProductListBean());
//        addData(new MallBean.KtProductListBean());
//        addData(new MallBean.KtProductListBean());
//        addData(new MallBean.KtProductListBean());
    }

    @Override
    protected void convert(BaseViewHolder helper, ShopDetailBean.ComListBean item) {
//        helper.setText(R.id.tv_goods_name, String.valueOf(item.getTradename()));
//
//        String price = "";
//        if (!TextUtils.isEmpty(item.getPrice()) && Double.parseDouble(item.getPrice()) != 0.00) {
//            price += item.getPrice();
//            price += "KT";
//        }
//        if (!TextUtils.isEmpty(item.getMarket_price()) && Double.parseDouble(item.getMarket_price()) != 0.00) {
//            if (!TextUtils.isEmpty(price)) {
//                price += "+";
//                price += item.getMarket_price();
//                price += "消费积分";
//            } else {
//                price += item.getMarket_price();
//                price += "消费积分";
//            }
//        }
//        if (TextUtils.isEmpty(price)) {
//            price = "0.00KT";
//        }
//        helper.setText(R.id.tv_goods_price, price);
        helper.setText(R.id.tv_user_evaluate_user, item.getNickname());
        helper.setText(R.id.tv_goods_name, item.getContent());
        final ImageView ivUserHead = helper.getView(R.id.iv_user_head);
        if (!TextUtils.isEmpty(item.getUseravatar())) {
            GlideUtils.loadCircleImg(mContext, ivUserHead, item.getUseravatar(), R.mipmap.icon_evaluate_head);
        } else {
            GlideUtils.loadCircleImg(mContext, ivUserHead, R.mipmap.icon_evaluate_head);
        }
        final ImageView ivGoodsBanner = helper.getView(R.id.iv_goods_banner);
        String imgCom = "";
        if (!TextUtils.isEmpty(item.getImg())) {
            imgCom = item.getImg().split(",")[0];
        }
        if (!TextUtils.isEmpty(imgCom)) {
            GlideUtils.loadRoundImg(mContext, ivGoodsBanner, imgCom, R.mipmap.default_foods_icon, 4);
        } else {
            ivGoodsBanner.setVisibility(View.GONE);
        }
        RelativeLayout rootView = helper.getView(R.id.ll_item_view);
        if (helper.getAdapterPosition() == 0) {
            rootView.setPadding(ScreenUtil.dip2px(mContext, 10), 0, 0, 0);
        } else if (helper.getAdapterPosition() == getData().size() - 1) {
            rootView.setPadding(0, 0, ScreenUtil.dip2px(mContext, 10), 0);
        } else {
            rootView.setPadding(0, 0, 0, 0);
        }
    }
}
